class TmuxSessionizer < Formula
  desc "Tool for opening git repositories as tmux sessions"
  homepage "https://github.com/jrmoulton/tmux-sessionizer/"
  url "https://github.com/jrmoulton/tmux-sessionizer/archive/refs/tags/v0.4.4.tar.gz"
  sha256 "9dfbe99a3c1fe7f48be0c1ab9056e49f36c4f85d023e24f874254f6791a9894e"
  license "MIT"
  revision 2

  bottle do
    sha256 cellar: :any,                 arm64_sequoia: "36296ed7973d20aa0bb90e6b500a0136ed4f367553608f2c4dd1ef658345523f"
    sha256 cellar: :any,                 arm64_sonoma:  "53b15bddb62d79bde6f63a5cfc18910fee1e0c3f7201ee7c9dd1e0aab367ace9"
    sha256 cellar: :any,                 arm64_ventura: "f0eadc021f990f7d2db80142244a4eb679aa1125984589e50b77b6d8a6d9c2a3"
    sha256 cellar: :any,                 sonoma:        "10ee6f3d53591391cb711b5ed9876bc152a4bdaddb9488ab0bd27315f6c98fc5"
    sha256 cellar: :any,                 ventura:       "9369b6cea10b3b085a0d92fd59dba3e9951ab319e378f1b4a47e02623b67a038"
    sha256 cellar: :any_skip_relocation, x86_64_linux:  "e65235329ebce9f8e96e603c471bcab6b377234c6a90171b837fce670f617ecf"
  end

  depends_on "pkgconf" => :build
  depends_on "rust" => :build
  depends_on "libgit2"
  depends_on "libssh2"
  depends_on "openssl@3"

  uses_from_macos "zlib"

  # patch to use libgit2 1.9, upstream pr ref, https://github.com/jrmoulton/tmux-sessionizer/pull/144
  patch :DATA

  def install
    # Ensure that the `openssl` crate picks up the intended library.
    ENV["OPENSSL_DIR"] = Formula["openssl@3"].opt_prefix
    ENV["OPENSSL_NO_VENDOR"] = "1"

    ENV["LIBGIT2_NO_VENDOR"] = "1"
    ENV["LIBSSH2_SYS_USE_PKG_CONFIG"] = "1"

    system "cargo", "install", *std_cargo_args

    generate_completions_from_executable(bin/"tms", "--generate")
  end

  test do
    require "utils/linkage"

    assert_match "Configuration has been stored", shell_output("#{bin}/tms config -p /dev/null")
    assert_match version.to_s, shell_output("#{bin}/tms --version")

    [
      Formula["libgit2"].opt_lib/shared_library("libgit2"),
      Formula["libssh2"].opt_lib/shared_library("libssh2"),
      Formula["openssl@3"].opt_lib/shared_library("libssl"),
      Formula["openssl@3"].opt_lib/shared_library("libcrypto"),
    ].each do |library|
      assert Utils.binary_linked_to_library?(bin/"tms", library),
             "No linkage with #{library.basename}! Cargo is likely using a vendored version."
    end
  end
end

__END__
diff --git a/Cargo.lock b/Cargo.lock
index 2274afd..18ec520 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,6 @@
 # This file is automatically @generated by Cargo.
 # It is not intended for manual editing.
-version = 3
+version = 4

 [[package]]
 name = "aho-corasick"
@@ -392,9 +392,9 @@ dependencies = [

 [[package]]
 name = "git2"
-version = "0.19.0"
+version = "0.20.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724"
+checksum = "3fda788993cc341f69012feba8bf45c0ba4f3291fcc08e214b4d5a7332d88aff"
 dependencies = [
  "bitflags",
  "libc",
@@ -496,9 +496,9 @@ checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"

 [[package]]
 name = "libgit2-sys"
-version = "0.17.0+1.8.1"
+version = "0.18.0+1.9.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224"
+checksum = "e1a117465e7e1597e8febea8bb0c410f1c7fb93b1e1cddf34363f8390367ffec"
 dependencies = [
  "cc",
  "libc",
diff --git a/Cargo.toml b/Cargo.toml
index d1ebcd4..bbf59e3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,7 +17,7 @@ exclude = ["images/*"]

 [dependencies]

-git2 = { version= "0.19", features = [ "vendored-openssl" ] }
+git2 = { version= "0.20", features = [ "vendored-openssl" ] }
 clap = { version = "4.5", features = ["cargo", "derive"] }
 serde_derive = "1.0"
 serde = "1.0"
